package io.shdxhl.simplerpc.client.proxy;

import io.shdxhl.simplerpc.code.proxy.ProxyFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cglib.proxy.Enhancer;
import org.springframework.stereotype.Component;

/**
 * 实现初始化代理类
 */
@Slf4j
@Component
public class RequestProxyFactory implements ProxyFactory {
    @Override
    public <T> T newProxyInstance(Class<T> clazz) {
        Enhancer enhancer = new Enhancer();
        enhancer.setSuperclass(clazz);
        enhancer.setCallback(new CglibProxyCallBackHandler());
        return (T)  enhancer.create();
    }
}
